function Publisher(){
   this.listener={}

   this.on=function (name, fn){
      if(!this.listener.hasOwnProperty(name)){
         this.listener[name] = [fn]
      }else{
         this.listener[name] = this.listener[name].push(fn)
      }
      return this;
   }
   this.once = function (){

   }
   // emit传入方法名和参数值
   this.emit=function (name,...args){
      let _this = this
      if(!this.listener.hasOwnProperty(name)){
         return new Error('name is not in listener')
      }
      this.listener[name].forEach(fn => {
         console.log(fn)
         fn.call(_this,...args)
      })
      return this;
   }
}

function add(a, b){
   console.log(a + b )
}
function sub(a, b){
   console.log(a - b)
}

const p = new Publisher()
p.on('add',add)
p.on('sub', sub)

p.emit('add',1,2)
p.emit('sub', 2,1)
p.emit('ohoho',1,2)
